<html>

<head>

<?php

include "../includes/constants.php";
include "../includes/db_schema.php";
	CreateTableSchema(npc_types);

function SimpleNPCtd($FieldNum,$DisplayName="",$InputSize="1") {
	global $Schema;
	global $db_row_npctypes_get;
	$FieldName = $Schema["npc_types"][$FieldNum]["COLUMN_NAME"];
	$DefaultValue = $db_row_npctypes_get[$FieldName];
	if ($DisplayName == "") {$DisplayName = ucfirst($FieldName);};
	echo "\t\t<td title=\"" . $FieldName . " (" . $FieldNum . ")\">" . $DisplayName . "</td>
		<td title=\"" . $FieldName . " value\"><input type=\"text\" size=\"" . $InputSize . "\" name=\"" . $FieldNum . "\" value=\"" . $DefaultValue . "\"></td>\n";
};

function SimpleNPCtext($FieldNum,$DisplayName="",$InputSize="1") {
	global $Schema;
	global $db_row_npctypes_get;
	$FieldName = $Schema["npc_types"][$FieldNum]["COLUMN_NAME"];
	$DefaultValue = $db_row_npctypes_get[$FieldName];
	if ($DisplayName == "") {$DisplayName = ucfirst($FieldName);};
	echo $DisplayName . ": <input type=\"text\" size=\"" . $InputSize . "\" name=\"" . $FieldNum . "\" value=\"" . $DefaultValue . "\">\n";
};

?>

<title>EQ Emu - Edit NPC</title>

<script src="../includes/functions.js"></script>

</head>

<body>

<?php

if ($_POST) {
	$query_post = "UPDATE npc_types SET ";
	foreach ($Schema["npc_types"] as $Key => $Value) {
		if (!is_numeric($Key)) $query_post .= $Key . "='" . $_POST[$Key] . "', ";
	};
	$query_post = substr($query_post,0,-2);	// Erase last comma
	$query_post .= " WHERE id='" . $_GET["id"] . "'";
	if (@mysql_query($query_post,$db)) {
		echo "<font color=\"blue\">\"" . $_POST[1] . "\" Updated Successfully!</font><br>\n";
	} else {
		echo "<font color=\"red\">Update Failed!</font> - [<font color=\"silver\">" . mysql_error() . "</font>]<br>\n";
	};
};

if (isset($_GET["id"]) && ($_GET["id"] != "")) {

$query_npctypes_get = "SELECT * FROM npc_types WHERE id='" . $_GET["id"] . "'";
$result_npctypes_get = mysql_query($query_npctypes_get,$db);
$db_row_npctypes_get = mysql_fetch_array($result_npctypes_get);

?>

<form method="POST" name="EditNPCType" action="">

<table border="0">
	<tr>
<?php SimpleNPCtd(0,'ID',3);?>
	</tr>
	<tr>
<?php SimpleNPCtd(1,'',32);?>
	</tr>
	<tr>
<?php SimpleNPCtd(2,'',32);?>
	</tr>
	<tr>
<?php SimpleNPCtd(3);?>
	</tr>
	<tr>
<?php SimpleNPCtd(4);?>
	</tr>
	<tr>
<?php SimpleNPCtd(5);?>
	</tr>
	<tr>
<?php SimpleNPCtd(6);?>
	</tr>
	<tr>
<?php SimpleNPCtd(8);?>
	</tr>
	<tr>
<?php SimpleNPCtd(9);?>
	</tr>
	<tr>
<?php SimpleNPCtd(10);?>
	</tr>
	<tr>
<?php SimpleNPCtd(11);?>
	</tr>
	<tr>
<?php SimpleNPCtd(14,'',3);?>
	</tr>
	<tr>
		<td title="merchant_id (15)">Merchant ID</td>
		<td title="merchant_id value">
			<input type="text" size="3" name="15" value="<?php echo $db_row_npctypes_get[15];?>">
			<button name="ViewMerchantList" onclick="LinkMerchantList(document.forms['EditNPCType'].elements[12].value); return false">View/Edit</button>
		</td>
<?php // SimpleNPCtd(15,'',3);?>
	</tr>
	<tr>
<?php SimpleNPCtd(16,'',3);?>
	</tr>
	<tr>
<?php SimpleNPCtd(17,'',3);?>
	</tr>
	<tr>
<?php SimpleNPCtd(18);?>
	</tr>
	<tr>
<?php SimpleNPCtd(19);?>
	</tr>
	<tr>
<?php SimpleNPCtd(20,'Special Attacks',3);?>
	</tr>
	<tr>
<?php SimpleNPCtd(21);?>
	</tr>
	<tr>
<?php SimpleNPCtd(22);?>
	</tr>
	<tr>
<?php SimpleNPCtd(23);?>
	</tr>
	<tr>
<?php SimpleNPCtd(24);?>
	</tr>
	<tr>
<?php SimpleNPCtd(25);?>
	</tr>
	<tr>
<?php SimpleNPCtd(26);?>
	</tr>
	<tr>
<?php SimpleNPCtd(27);?>
	</tr>
	<tr>
<?php SimpleNPCtd(28);?>
	</tr>
	<tr>
<?php SimpleNPCtd(29);?>
	</tr>
	<tr>
<?php SimpleNPCtd(30);?>
	</tr>
	<tr>
<?php SimpleNPCtd(31);?>
	</tr>
	<tr>
<?php SimpleNPCtd(37);?>
	</tr>
	<tr>
<?php SimpleNPCtd(38);?>
	</tr>
	<tr>
<?php SimpleNPCtd(39);?>
	</tr>
	<tr>
<?php SimpleNPCtd(41);?>
	</tr>
	<tr>
<?php SimpleNPCtd(42);?>
	</tr>
	<tr>
<?php SimpleNPCtd(43);?>
	</tr>
	<tr>
<?php SimpleNPCtd(44);?>
	</tr>
	<tr>
<?php SimpleNPCtd(7,'HP',4);?>
	</tr>
	<tr>
		<td>Regen</td>
		<td>
<?php SimpleNPCtext(12,'HP');?>
<?php SimpleNPCtext(13,'Mana');?>
		</td>
	</tr>
	<tr>
<?php SimpleNPCtd(40);?>
	</tr>
	<tr>
		<td>Base Stats</td>
		<td>
<?php SimpleNPCtext(45);?>
<?php SimpleNPCtext(46);?>
<?php SimpleNPCtext(47);?>
<?php SimpleNPCtext(48);?>
<?php SimpleNPCtext(49,'INT');?>
<?php SimpleNPCtext(50);?>
<?php SimpleNPCtext(51);?>
		</td>
	</tr>
	<tr>
		<td>Resists</td>
		<td>
<?php SimpleNPCtext(32);?>
<?php SimpleNPCtext(33);?>
<?php SimpleNPCtext(34);?>
<?php SimpleNPCtext(35);?>
<?php SimpleNPCtext(36);?>
		</td>
	</tr>
	<tr>
<?php SimpleNPCtd(52);?>
	</tr>
	<tr>
<?php SimpleNPCtd(53);?>
	</tr>
	<tr>
<?php SimpleNPCtd(54);?>
	</tr>
</table>

<button type="submit">Update</button>
<button type="reset">Reset</button>

</form>

<?php

} else {
	echo "<form name=\"NoID\" method=\"GET\" action=\"\">Enter ID: <input type=\"text\" name=\"id\" size=\"3\"><br>\n";
};

?>

</body>

</html>